<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

function recurse_copy($src,$dst) {
	$dir = opendir($src);
	@mkdir($dst);
	while(false !== ( $file = readdir($dir)) ) {
		if (( $file != '.' ) && ( $file != '..' )) {
			if ( is_dir($src . '/' . $file) ) {
				recurse_copy($src . '/' . $file,$dst . '/' . $file);
			}
			else {
				copy($src . '/' . $file,$dst . '/' . $file);
			}
		}
	}
	closedir($dir);
}

$sql = '';
$column_payer_existed = false;
$column_plugin_existed = false;

$query = DB::query("SHOW COLUMNS FROM ".DB::table('common_payment_order'));
while($temp = DB::fetch($query)) {
	if($temp['Field'] == 'payer') {
		$column_payer_existed = true;
		continue;
	}
	if($temp['Field'] == 'plugin') {
		$column_plugin_existed = true;
		continue;
	}
}
$sql .= !$column_payer_existed ? "ALTER TABLE ".DB::table('common_payment_order')." ADD COLUMN payer varchar(50) DEFAULT NULL;\n" : '';
$sql .= !$column_plugin_existed ? "ALTER TABLE ".DB::table('common_payment_order')." ADD COLUMN plugin varchar(15) DEFAULT NULL;\n" : '';

if($sql) {
	runquery($sql);
}

recurse_copy(DISCUZ_ROOT . 'source/plugin/unifiedpay/install/payment', DISCUZ_ROOT . 'api/payment');

$finish = TRUE;
?>